using System.Drawing;

namespace OpenComposite.Base.Designer
{
	public abstract class Connector : Symbol, IConnector
	{
		#region Initialization
		public Connector()
		{
			init();
		}
		private void init()
		{
			this.BeginUpdate();

			this.NameTextBox.ReadOnly = true;
			this.NameTextBox.Visible = false;

			this.EndUpdate();
		}
		#endregion

		#region Public Members

		public override bool UseGrid
		{
			get
			{
				return false;
			}
		}

		#region IConnector Members

		public override Point GetRouteStart(RouteDockDirection dock, Route route)
		{
			return getDefaultDockPoint(dock);
		}
		public override Point GetRouteEnd(RouteDockDirection dock, Route route)
		{
			return getDefaultDockPoint(dock);
		}

		#endregion

		#endregion

		#region Private Members

		#region Methods
		private Point getDefaultDockPoint(RouteDockDirection dock)
		{
			Rectangle bounds = this.GetPaintBounds();
			Point p = new Point();
			switch ( dock ) {
				case RouteDockDirection.Top:
					p.X = bounds.Left + ( ( bounds.Right - bounds.Left ) / 2 );
					p.Y = bounds.Top;
					break;
				case RouteDockDirection.Bottom:
					p.X = bounds.Left + ( ( bounds.Right - bounds.Left ) / 2 );
					p.Y = bounds.Bottom;
					break;
				case RouteDockDirection.Right:
					p.X = bounds.Right;
					p.Y = bounds.Top + ( ( bounds.Bottom - bounds.Top ) / 2 );
					break;
				case RouteDockDirection.Left:
					p.X = bounds.Left;
					p.Y = bounds.Top + ( ( bounds.Bottom - bounds.Top ) / 2 );
					break;
			}
			return p;
		}
		#endregion

		#endregion
	}
}
